Merged
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add initial implementation for AI client in WordPress
Implement wp ai credentials command for managing AI provider API keys
Dec 15, 2025
This comment was marked as resolved.
This comment was marked as resolved.
- Use wp_ai_client_provider_credentials option as per API_Credentials_Manager - Add wp ai generate text/image commands for AI content generation - Add wp ai check command to verify prompt support - Add tests for new commands Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
- Add proper type hints for Prompt_Builder parameters - Use json_encode instead of wp_json_encode for consistency - Add path validation for image output to prevent writing to system directories - Use strict base64 decoding for better error handling Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Check for directory traversal (..) before resolving paths - Validate base64 format with regex before decoding - Add size limit check (50MB) to prevent memory exhaustion - Verify parent directory exists before attempting file write - Improve error messages for better debugging Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…stant - Replace regex validation with PHP's native base64_decode strict mode - Add MAX_IMAGE_SIZE_BASE64 constant for clarity and maintainability - Simplify base64 validation logic to rely on built-in strict validation - Improve error messages for better user feedback Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Use realpath() to fully resolve paths and prevent all traversal attacks (including URL-encoded) - Reconstruct safe output path using resolved parent dir + basename - Add json_encode() error handling with descriptive messages - Ensure is_dir() check for parent directory validation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Add Windows system directory protection (C:\Windows, C:\Program Files) - Use case-insensitive path comparison for Windows compatibility - Separate MAX_IMAGE_SIZE_BYTES constant for better clarity - Improve documentation for size constants with detailed explanation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
Implement wp ai credentials command for managing AI provider API keys
Implement complete wp ai command with credentials management and content generation
Dec 15, 2025
This comment was marked as resolved.
This comment was marked as resolved.
- Add --provider flag mapping to using_provider() - Update --model flag to support comma-separated list of model preferences - Add --max-tokens flag mapping to using_max_tokens() - Add --system-instruction flag mapping to using_system_instruction() - Add validation tests for new options - Update documentation with examples for all new flags Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
- Replace call_user_func_array with spread operator syntax - Cleaner and more readable code - Better performance with modern PHP Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Remove trailing whitespace for coding standards compliance - Cache count() result before loop to avoid repeated function calls - Minor performance and style improvements Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
- Implement status command to display table of supported AI capabilities - Check text generation and image generation support - Support multiple output formats (table, csv, json, yaml) - Add test scenario for status command - Update class documentation with status command example Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
- Add ensure_ai_client_available() helper method to follow DRY principle - Update generate, check, and status methods to use helper - Add CAPABILITY_CHECK_PROMPT constant for clarity - Improve code maintainability and reduce duplication Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Extract FORBIDDEN_PATHS constant for better maintainability - Improve comment conciseness - Use case-sensitive check for Unix paths, case-insensitive for Windows - Prevent false positives on case-sensitive filesystems Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Use more robust Windows path detection (checks for :\\ instead of C:\\) - Handles all drive letters (D:\\, E:\\, etc.) - Clarify comment about using constant for consistency Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Clarify that capability detection is based on configured providers - Document that prompt content doesn't affect capability detection logic - Improve code documentation for better understanding Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Member
|
@copilot Add new args for the generation command:
|
- Add --top-p flag for nucleus sampling (value between 0.0 and 1.0) - Add --top-k flag for top-k sampling (positive integer) - Map to using_top_p() and using_top_k() Prompt_Builder methods - Add validation for both parameters - Add example usage in documentation - Add Behat tests for parameter validation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Contributor
Author
Added Features:
|
swissspidy
approved these changes
Dec 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a complete WP-CLI command for the WordPress AI Client library, including credential management and AI content generation capabilities with full Prompt_Builder API support.
Implementation
Credentials Management
Credentials_Commandclass with CRUD operations:list- displays all stored credentials with masked API keysget <provider>- retrieves specific provider credentialsset <provider> --api-key=<key>- stores/updates credentialsdelete <provider>- removes credentialsStorage: Credentials persisted in
wp_ai_client_provider_credentialsWordPress option (matchesAPI_Credentials_Manager)Security: API keys masked in output (first 3 + last 4 chars visible)
Output formats: table, JSON, YAML, CSV via
--formatflagAI Content Generation & Status
AI_Commandclass with generation and status operations:status- displays table of supported AI capabilities (Text Generation, Image Generation)generate text <prompt>- generates text from AIgenerate image <prompt>- generates images from AIcheck <prompt>- verifies if a prompt is supported for text/image generationComplete Prompt_Builder API Integration with all configuration options:
--model=<models>- Comma-separated list of model preferences (e.g., "openai,gpt-4,anthropic,claude-3") →using_model_preference()--provider=<provider>- Specific AI provider →using_provider()--temperature=<temp>- Temperature control (0.0-2.0) →using_temperature()--top-p=<top-p>- Top-p/nucleus sampling (0.0-1.0) →using_top_p()--top-k=<top-k>- Top-k sampling (positive integer) →using_top_k()--max-tokens=<tokens>- Maximum tokens to generate →using_max_tokens()--system-instruction=<instruction>- System instruction to guide AI behavior →using_system_instruction()--output=<file>- Save generated images to file--format=<format>- Output format (text/json for generation, table/csv/json/yaml for status)Security: Production-grade path validation, base64 strict validation, cross-platform system directory protection
Size limits: 50MB maximum for image data with configurable constants
Usage
Security
realpath()resolutionTesting
Comprehensive Behat test coverage for all commands including success/error paths, output formatting, validation scenarios, and edge cases.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.